<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="68px"
    >
      <el-form-item label="最低充值" prop="limit_min_deposit_amount">
        <el-input
          v-model="queryParams.limit_min_deposit_amount"
          placeholder="请输入最低充值"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="充值日期" prop="date_range">
        <el-date-picker
          v-model="queryParams.date_range"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="团队等级" prop="team_type">
        <el-select
          v-model="queryParams.team_type"
          placeholder="团队等级"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.customer_team_deposit_type"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary" icon="el-icon-search" size="mini"
          v-hasPermi="['customer:user:query']" @click="handleQuery"
        >
          搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-close"
          size="mini"
          @click="handleClose"
        >关闭
        </el-button>
        <span style="margin-left: 50px">总充值金额：{{ total_deposit_amount }}</span>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList" @sort-change="sortChange">
      <el-table-column sortable="custom" label="用户编号" align="center" key="id" prop="id" width="100"/>
      <el-table-column label="用户名称" align="center" key="name" prop="name"
                       :show-overflow-tooltip="true"
      />
      <el-table-column label="充值金额" align="center" key="deposit_amount" prop="deposit_amount"
                       :show-overflow-tooltip="true"
      />
      <el-table-column label="创建时间" align="center" key="register_time" prop="register_time" width="160"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.page_size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listTeamDeposit} from '@/api/customer/teamDeposit'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'

export default {
  name: 'TeamDeposit',
  computed: {},
  dicts: ['customer_team_deposit_type'],
  components: {},
  data() {
    return {
      // 遮罩层
      loading: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      dataList: null,
      // 弹出层标题
      title: '',
      exchangeTitle: '',
      // 弹出层标题
      resetTitle: '',
      resetTradeTitle: '',
      // 是否显示弹出层
      open: false,
      exchangeOpen: false,
      // 是否显示弹出层
      resetPwdOpen: false,
      resetTradePwdOpen: false,
      admin: false,
      appOptions: [],
      // 表单参数
      form: {},
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      // 查询参数
      queryParams: {
        page: 1,
        page_size: 10,
        team_type: 1,
        limit_min_deposit_amount: undefined,
        date_range: undefined,
        begin_deposit_time: undefined,
        end_deposit_time: undefined,
        customer_id: undefined,
      },
      customer_id: undefined,
      // 表单校验
      rules: {},
      total_deposit_amount: 0.00,
    }
  },
  created() {
    this.customer_id = this.$route.params && this.$route.params.customerId;
    this.getList()
  },
  methods: {
    sortChange(column) {
      if (column) {
        if (column.order === 'ascending') {
          this.queryParams.sort_list = [{sort_by: column.prop, sort_type: 1}]
        } else if (column.order === 'descending') {
          this.queryParams.sort_list = [{sort_by: column.prop, sort_type: 2}]
        }
        // this.getList()
      }
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true
      this.queryParams.customer_id = this.customer_id
      if (this.queryParams.date_range) {
        this.queryParams.begin_deposit_time = this.queryParams.date_range[0]
        this.queryParams.end_deposit_time = this.queryParams.date_range[1]
      }
      listTeamDeposit(this.queryParams).then(response => {
          this.dataList = response.data
          this.total = response.total
          this.total_deposit_amount = response.total_deposit_amount
          this.loading = false
        }
      )
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.createTimeRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 返回按钮操作 */
    handleClose() {
      const obj = {path: "/customer/customerUser"};
      this.$tab.closeOpenPage(obj);
    }
  }
}
</script>
